package com.feeyo.groundservice.base_util.loading

import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.AppUtils
import com.lxj.xpopup.XPopup
import com.lxj.xpopup.core.BasePopupView

/**
 *作者：QLH on 2022-10-17
 *描述：自定义loading
 */
object LoadingPlanViewUtil : ILoading {

    private var loading: BasePopupView? = null

    override fun show(msg: String?,dissmissOnBackPressed:Boolean) {
        if (loading?.isShown == true) loading?.dismiss()//清除前一个loading
        if (!AppUtils.isAppForeground()) return

        loading = XPopup.Builder(ActivityUtils.getTopActivity())
            .dismissOnTouchOutside(false)
            .isLightNavigationBar(true)
            .dismissOnBackPressed(dissmissOnBackPressed)
            .hasShadowBg(true)
            //.hasBlurBg(true)
            .asCustom(LoadingPlanView(ActivityUtils.getTopActivity(), msg))
        loading?.show()
    }

    override fun close() {
        loading?.dismiss()
    }

    override fun smartClose() {
        loading?.smartDismiss()
    }
}